<?php 
if(!isset($MAIN)){
	include_once("includes/class.ibnfm.php");
	$MAIN = new MAIN();
}
if(isset($_REQUEST['del'])){
	$MAIN->notes->delNote($_REQUEST['del']);
	?>
	<script type="text/javascript">
	ajaxGet('notes.php','rel_table=<?php echo($_REQUEST['rel_table']);?>&rel_id=<?php echo($_REQUEST['rel_id']);?>',$('cnt_notes'));
	</script>
	<?php
	exit();
}
$table = $_REQUEST['rel_table'];
$id = $_REQUEST['rel_id'];
$notes = $MAIN->notes->getNotes($table,$id);
if(count($notes)>0){
?>
<table cellspacing="0" cellpadding="0" style="margin: 0px;" class="list">
	<tr>
		<th>datum</th>
		<th>meddelande</th>
		<th>av</th>
		<th></th>
	</tr>	
<?php 
foreach($notes as $note){
?>
	<tr class="entry">
		<td style="width: 70px;">
			<span class="date"><?php echo(date('Y-m-d',strtotime($note['modif'])));?></span>
		</td>
		<td>
		<span class="title_course">
		<?php echo($note['field2']);?>
		</span>
		</td>
		<td>
			<?php echo($av = ($note['fullname']!='')?$note['fullname']:$note['email']);?>
		</td>
		<td style="width:20px;">
			<?php
			if($note['user_id']==$MAIN->currentUser['id']){
			?>
			<img class="btn_img" src="images/btn_admin_del.png" alt="ta bort" title="ta bort" onclick="delNote(<?php echo($note['id']);?>);"/>
			<?php
			}else{
			?>
			<img class="btn_img off" src="images/btn_admin_del_off.png" alt="ta bort" title="ta bort"/>
			<?php
			}
			?>
		</td>
	</tr>
<?php 
}
?>
</table>
<script type="text/javascript">
var delNote=function(id){
	var msg = 'Bekräfta borttagningen!';
	if(confirm(msg)){
		ajaxGet('notes.php','del='+id+'&rel_table=<?php echo($table);?>&rel_id=<?php echo($id);?>');				
	}
}
</script>
<?php 
}
?>